Overview
fix_jp2_v2 is a specialized utility that corrects malformed GeoTIFF projection metadata in HiRISE (High Resolution Imaging Science Experiment) JPEG2000 files. It specifically fixes Equirectangular projections that were incorrectly encoded with CenterLatGeoKey instead of StandardParallel1GeoKey.
This tool performs in-place binary editing of GeoJP2 headers without decompressing or recompressing the imagery, making it extremely fast.
The Problem
Historically, some HiRISE GeoJP2 files were generated with incorrect GeoTIFF projection parameters for Equirectangular projections. According to the GeoTIFF specification:- Incorrect: Using
CenterLatGeoKey(tag 3089) - Correct: Using
StandardParallel1GeoKey(tag 3078)
Related Issue
GDAL Ticket #2706Installation
Pre-compiled Windows Executable
A Windows executable (fix_jp2_v2.exe) is included in the repository:
Compile from Source
On Linux, macOS, or Windows with GCC:No external libraries required - uses only standard C/C++ libraries.
Usage
Parameters
Path to the HiRISE JPEG2000 file to fix. The file is modified in-place.
How It Works
Locate GeoTIFF Header
Scans the first 10KB of the JP2 file for the embedded TIFF header within the UUID box.
Check for Existing Fix
Searches for
StandardParallel1GeoKey (3078). If found, exits without changes.Examples
Fix Single File
Batch Processing
Linux/macOS:Verify Fix with GDAL
Before:standard_parallel_1 parameter in the output.
Technical Details
File Format Constraints
- GeoTIFF data must be within the first 10KB of the JP2 file
- Does not validate that the file actually uses Equirectangular projection
- Does not modify image data or recompress JPEG2000 stream
What Gets Modified
Only 2 bytes in the GeoKey directory are changed:Safety
Backup Recommended: While the tool only modifies 2 bytes, it’s good practice to keep backups of original files before batch processing.
- Opens files in read-write binary mode (
rb+) - Only writes 2 bytes at the specific tag location
- Does not modify files that already have correct tags
- Exits with error if GeoTIFF structure is not found
Error Messages
| Error | Meaning | Solution |
|---|---|---|
Failed to open file | File not found or no read/write permissions | Check path and permissions |
Did not find TIFF header | Not a GeoJP2 file or GeoTIFF data not in first 10KB | File may not be a GeoJP2 or is corrupted |
Failed to find GEOKEYDIRECTORY tag | No GeoTIFF projection info | File lacks geospatial metadata |
Unable to find target tag (3089 / CenterLat) | Already uses correct tag or different projection | No fix needed |
StdParallel1GeoKey already exists | File already corrected | No action taken (v2 behavior) |
HiRISE Background
HiRISE (High Resolution Imaging Science Experiment) is a camera aboard NASA’s Mars Reconnaissance Orbiter that captures images at resolutions up to 25-30 cm/pixel.HiRISE Data Products
- Observation IDs:
ESP_######_####orPSP_######_#### - Standard Products: Red-band, color (IRB/RGB), and DTMs
- Projections: Typically Equirectangular for regional maps
- Formats: JPEG2000 for web distribution, ISIS cubes for processing
When to Use This Tool
Usefix_jp2_v2 for:
- Legacy HiRISE JP2 files (pre-2023) with projection issues
- Downloaded JP2 files that GDAL reports incorrect projection
- Files showing
CenterLatGeoKeywhenStandardParallel1GeoKeyis expected
Current HiRISE Data: Files processed after January 2023 by the HiRISE team should already have correct projection tags and won’t need fixing.
Verification Script
Check if a file needs fixing:Script Location
Additional Resources
Credits
Author: Frank Warmerdam (warmerdam@pobox.com)v2 Update: Trent Hare (thare@usgs.gov) - January 2023 License: Public Domain
This tool is provided as-is for the planetary science community. Always validate outputs after processing.